<?php
include('../../include/functions.inc.php');
include('../../include/inputbuilder.inc.php');
include('../../include/maintenance.inc.php');

if( isEmpty(getParam('ID')) ) {
    echo 'WRONG PARAMETER';
}
else {
    ?>
    <style type="text/css">
        .line0 {
             background-color: #FFFFFF;
        }
    </style>
    <?php
    
    $intID = getParam('ID');
    
    $mEmpresas = unserialize($_SESSION['mEmpresas']);

    $builder = new InputBuilder();
    $builder->db = $db;
    $tabs = $db->query_select('cllg_table_tab', "TABLE_NAME='cllg_empresa'");
    $rows = $db->query_select('cllg_empresa', sprintf("ID='%s'", $intID));
    $arrEstudiantes = $db->query_select('cllg_student', "FK_EMPRESA = {$intID}", 'ID');
    foreach ($rows as $row) {
        ?>
        <form id="<?php echo $mEmpresas->formName; ?>" name="<?php echo $mEmpresas->formName; ?>" method="POST" action="<?php echo $mEmpresas->updateUrlPage; ?>">
            <div id="panel" class="">
                <ul class="nav nav-tabs" style="font-weight:bolder">
                    <?php
                    $ix = 0;
                    foreach ($tabs as $t) {
                        $ix++;
                        ?>
                    <li class="active" tabindex="<?php echo $ix; ?>"><a><?php echo $t["CAPTION"]; ?></a></li>
                        <?php
                    }
                    $ix++;
                    ?>
                    <li class="active" tabindex="<?php echo $ix; ?>"><a>ESTUDIANTES</a></li>
                </ul>
                <div class="">
                    <?php
                    $ix = 0;
                    foreach ($tabs as $t) {
                        $ix++;
                        ?>
                        <div class="">
                            <table class=""  width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <th scope="col">
                                    <div style="margin-left:60%" class="btn-group">
                                        <input type="button" name="cmdOk" class="btn btn-info"  id="cmdOk" value="Guardar" onClick="javascript:formOkBt($(this.form),updateAction);jQuery('#cmAddcontainer').show();" />
                                        <input type="button" name="eliminar" id="eliminar" onclick="javascript:deleteAction('<?php echo $mEmpresas->deleteUrlPage; ?>',<?php echo $mEmpresas->getDeleteUrl(); ?>);jQuery('#cmAddcontainer').show();" value="Eliminar" class="btn btn-info" />
                                        <input type="button" name="cmdCancel" id="cmdCancel" value="Cancelar" class="btn btn-info" onClick="loadTable();jQuery('#cmAddcontainer').show();" />
                                    </div>
                                    </th>
                                </tr>
                                <tr>
                                    <td>
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <?php
                                            if ($ix == 1) {
                                                ?>  
                                                <tr>
                                                    <td width="25%">CORPORACIÓN</td>
                                                    <td width="75%">
                                                        <input name="CORPORACION" type="text" value="<?php print $row['CORPORACION']; ?>" id="CORPORACION" size="100" maxlength="255" />
                                                        <input name="ID" type="hidden" id="ID" value="<?php print $row['ID']; ?>" />
                                                        <input name="STATUS" type="hidden" id="STATUS" value="<?php print $row['STATUS']; ?>" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>* NOMBRE</td>
                                                    <td>
                                                        <input name="NOMBRE" type="text" value="<?php print $row['NOMBRE']; ?>" id="NOMBRE" size="100" maxlength="255" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>* DIRECCIÓN</td>
                                                    <td>
                                                        <textarea name="DIRECCION" type="text" id="DIRECCION" size="100" rows="4" maxlength="255" ><?php echo $row['DIRECCION']; ?></textarea>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>WEB</td>
                                                    <td>
                                                        <input name="WEB" type="text" value="<?php print $row['WEB']; ?>" id="WEB" size="100" maxlength="255" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>PBX</td>
                                                    <td>
                                                        <input name="PBX" type="text" value="<?php print $row['PBX']; ?>" id="PBX" size="100" maxlength="255" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>OBSERVACIÓN</td>
                                                    <td>
                                                        <textarea name="OBSERVACION" type="text" id="OBSERVACION" rows="5" size="100" maxlength="255"><?php echo $row['OBSERVACION']; ?></textarea>
                                                    </td>
                                                </tr>
                                                <?php
                                            }
                                            $builder->build("cllg_empresa", getParam('ID'), $t['ID']);
                                            ?>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td>&nbsp;</td>
                                </tr>
                            </table>
                        </div>
                        <?php
                    }
                    ?>
                    <div class="TabbedPanelsContent">
                        <table class="table table-hover table-bordered table-striped" width="100%" cellspacing="1" cellpadding="0" border="0">
                            <tr>
                                <th>Carnet</th>
                                <th>1er nombre</th>
                                <th>2do nombre</th>
                                <th>Apellidos</th>
                                <th>Genero</th>
                            </tr>
                            <?php
                            $strClass = 'data line0';
                            if( count($arrEstudiantes) == 0 ) {
                                ?>
                                <tr class="<?php print $strClass; ?>">
                                    <td colspan="5">No hay estudiantes.</td>
                                </tr>
                                <?php
                            }
                            else { 
                                while( $arrTMP = each($arrEstudiantes) ) {
                                    ?>
                                    <tr class="<?php print $strClass; ?>">
                                        <td><?php print $arrTMP['value']['ID']; ?></td>
                                        <td><?php print $arrTMP['value']['FIRST_NAME']; ?></td>
                                        <td><?php print $arrTMP['value']['SECOND_NAME']; ?></td>
                                        <td><?php print $arrTMP['value']['LAST_NAME']; ?></td>
                                        <td><?php print $arrTMP['value']['GENDER']; ?></td>
                                    </tr>
                                    <?php
                                    $strClass = ($strClass == "data line0") ? 'data line1' : 'data line0'; 
                                }
                            }
                            ?>
                        </table>
                    </div> 
                </div>
            </div>
        </form>
        <?php
    }
    $_SESSION['fields'] = serialize($builder->fieldsArray);
}
?>